<!-- 用户管理 -->
<template>
    <div class="rightCenter">
        <div class="listTop">
            <div></div>
            <div class="listTopInpBox">
                <div class="listTopInpIco">
                    <i class="icon font_family icon-sousuo"></i>
                </div>
                <input class="listTopInp" type="text" v-model='searchVal' oninput='searchFun' placeholder="搜索姓名/手机号 ">
            </div>
        </div>
        <ul class="listUl">
            <li class="listLi fristLI">
                <div class="listDiv listOne">
                    账号
                </div>
                <div class="listDiv listTwo">
                    姓名
                </div>
                <div class="listDiv listThree">
                    手机号码
                </div>
                <div class="listDiv listFour">
                    家庭住址
                </div>
                <div class="listDiv listFive">
                    最后登录
                </div>
            </li>
            <li class="listLi dataLi" v-for="(item,index) in dataList" :class="{grayBack:index % 2 == 1}" :key='index'>
                <div class="listDiv listOne">
                    {{item.markno}}
                </div>
                <div class="listDiv listTwo">
                    {{item.custname}}
                </div>
                <div class="listDiv listThree">
                    {{item.mobile}}
                </div>
                <div class="listDiv listFour">
                    {{item.city}}
                </div>
                <div class="listDiv listFive">
                    {{item.lastTime | baseDateFun}}
                </div>
            </li>
        </ul>
        <div class="paging">
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pageNo" :page-sizes="[10, 20, 30, 40]"
                :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="totalVal">
            </el-pagination>
        </div>
    </div>
</template>
<script>
import { mapActions } from "vuex";
import integralRequest from "../../assets/integral";
export default {
  data() {
    return {
      searchVal: "", //所搜
      dataList: [],
      pageNo: 1, //页码
      pageSize: 10, //每页条数
      totalVal: 0 //总数量
    };
  },
  filters: {},

  created: function() {
    let self = this;
    if (sessionStorage.getItem("TABLIST")) {
      let arr = JSON.parse(sessionStorage.getItem("TABLIST"));
      console.log(arr);
      let routShow = false;
      for (let i = 0; i < arr.length; i++) {
        if (arr[i].name == "用户管理") {
          routShow = true;
        }
      }
      console.log(routShow);

      if (routShow == false) {
        this.$router.push({
          path: "/login"
        });
        sessionStorage.clear();
        self.$message("暂无权限");
        return;
      }
    } else {
      this.$router.push({
        path: "/login"
      });
      sessionStorage.clear();
      self.$message("暂无权限");
      return;
    }
    self.searchVal = "";
    this.searchFun();
  },
  watch: {
    searchVal(val) {
      this.searchFun(val);
    }
  },
  mounted() {},
  methods: {
    //搜索
    async searchFun() {
      let self = this;
      let params = {
        custname: self.searchVal,
        mobile: self.searchVal,
        page: self.pageNo,
        size: self.pageSize
      };
      let getParams = `custname=${params.custname}&mobile=${
        params.mobile
      }&page=${params.page}&size=${params.size}`;
      let res = await integralRequest.getuserPage(getParams);
      if (res.statusCode == 200) {
        self.dataList = [];
        if (res.data) {
          if (res.data.records) {
            self.dataList = res.data.records;
          }
          self.totalVal = res.data.total * 1;
        }
      } else {
        self.$message(res.statusMessage);
        self.dataList = [];
      }
    },
    //分页 - 每页条数
    handleSizeChange(val) {
      this.pageSize = val;
      this.searchFun();
    },
    //分页 - 页数
    handleCurrentChange(val) {
      this.pageNo = val;
      this.searchFun();
    }
  }
};
</script>
<style scoped>
.listOne {
  width: 20%;
}

.listTwo {
  width: 10%;
}

.listThree {
  width: 20%;
}

.listFour {
  width: 30%;
}

.listFive {
  width: 20%;
}
</style>